package gqlgen

import (
	"github.com/99designs/gqlgen/graphql/handler"
	"github.com/facebookgo/inject"
	"github.com/gin-gonic/gin"
	"github.com/shinedone/srv-framework/pkg/asserts"
	"github.com/shinedone/srv-framework/pkg/beans"
)

func NewGqlHandler() gin.HandlerFunc {
	r := &Resolver{}
	err := beans.Provide(&inject.Object{Value: r})
	asserts.Nil(err, err)
	srv := handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: r}))
	return func(c *gin.Context) {
		srv.ServeHTTP(c.Writer, c.Request)
	}
}
